﻿Public Class FrmMeslekler

	Protected Overrides Sub OnLoad(e As System.EventArgs)
		MyBase.OnLoad(e)
		ToolBar.Renderer = New FirefoxRenderer
		Populate()
	End Sub

	Private Sub Populate()
		List.DataSource = Service.Meslek.Liste
	End Sub

	Private Sub Populate(kod As String)
		Populate()
		Dim Row = (From r As DataGridViewRow In List.Rows Where r.Cells("kod").Value = kod).FirstOrDefault
		If Row Is Nothing Then Return
		Row.Highlight()
	End Sub

	Private Sub MnuClose_Click(sender As System.Object, e As System.EventArgs) Handles MnuClose.Click
		Close()
	End Sub

	Private Sub BtnNew_Click(sender As System.Object, e As System.EventArgs) Handles BtnNew.Click, MnuNew.Click
		Dim Form As New FrmMeslek
		If Form.ShowDialog <> Windows.Forms.DialogResult.OK Then Return
		Populate(Form.kod.Text)
	End Sub

	Private Sub MnuEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuEdit.Click
		If List.SelectedRows.Count <> 1 Then Return
		Dim Form As New FrmMeslek(List.SelectedRows(0).Cells("kod").Value)
		If Form.ShowDialog <> Windows.Forms.DialogResult.OK Then Return
		Populate(Form.Record.rowid)
	End Sub

	Private Sub List_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles List.DoubleClick
		MnuEdit.PerformClick()
	End Sub

	Private Sub List_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles List.KeyDown
		If e.KeyData = Keys.Enter Then
			MnuEdit.PerformClick()
			e.Handled = True
		End If
	End Sub

	Private Sub MnuDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuDelete.Click
		If List.SelectedRows.Count <> 1 Then Return
		If Service.Meslek.Kullanimda(List.SelectedRows(0).Cells("kod").Value) Then
			Warning("Bu meslek kodu daha önce kullanıldığı için silemezsiniz.")
			Return
		End If
		If Not Confirm("Bu kaydı silmek istediğinizden emin misiniz?") Then Return
		Table.Delete("meslek", List.SelectedRows(0).Cells("kod").Value, "kod")
		Populate()
	End Sub

End Class